<?php 
if(KT!='KhiThe') exit;
class supports_controller extends supports_model{
		
	public function __construct()
	{
		global $lang;
		$this->lang = $lang;
		parent::__construct();
		parent::addObject('khithe_template');
		parent::addObject('khithe_request');
		parent::addObject('khithe_string');
	}
	
	public function index_action()
	{
		$resultHtml = '';
		$strHtmlContent = $this->khithe_display('index');
		$arrBlockHtml = $this->khithe_getBlockHtml($strHtmlContent);
		$resultsupport = parent::getsupports();
		while( $row_supports = mysql_fetch_assoc($resultsupport) )
		{
			$arrsupport = array(
				"cell_ID"=>$row_supports['ID'],
				"cell_1"=>'<input name="delId[]" type="checkbox" value="'.$row_supports['ID'].'" />',
				"cell_2"=>$row_supports['Fullname'],
				"cell_3"=>$row_supports['Nick'],
				"cell_4"=>$row_supports['Kind'],
				"cell_5"=>$row_supports['Order'],
				"cell_6"=>$row_supports['Status']=='true'?$this->lang['enabled']:$this->lang['disabled'],
				"class_cell"=>$row_supports['Status']=='true'?"cell_groupitem1":"cell_groupitem_ex1",
			);
			$resultHtml .= $this->khithe_assign($arrBlockHtml['supports'],$arrsupport);
		} mysql_free_result($resultsupport);
		$strHtmlContent = $this->khithe_assignBlock($strHtmlContent, array('htmlCat'=>$resultHtml));
		$strHtmlContent = $this->khithe_assign($strHtmlContent, $this->lang);
		return $strHtmlContent;		
	}
	
	public function add_action()
	{	
		if($_GET['iframe']=='true')
		{
			$this->lang['sms'] ='';
			if(isset($_POST['txt_supports']))
			{
				$supportname = parent::checkStrMySQL($_POST['txt_supports']);
				$Email = parent::checkStrMySQL($_POST['txt_Email']);
				if($supportname==''){
					$this->lang['sms'] = $this->lang['Emptysupport'];
				}else{
					$done = parent::updateInsertsupport($_POST);
					if($done) $this->gotowinparent(url_base.'admin/supports');
				}
			}
						
			$this->lang['txt_supportsValue'] = isset($_POST['txt_supports'])?$_POST['txt_supports']:NULL;
			$this->lang['select_yahoo'] =(isset($_POST['kind']) && $_POST['kind']=='yahoo'?' selected="selected" ':'');
			$this->lang['select_skype'] =(isset($_POST['kind']) && $_POST['kind']=='skype'?' selected="selected" ':'');
			$this->lang['txt_FullnameValue'] = isset($_POST['txt_Fullname'])?$_POST['txt_Fullname']:NULL;
			$this->lang['txt_orderValue'] = isset($_POST['txt_order'])?$_POST['txt_order']:NULL;;
			$this->lang['active'] ='add';
			$this->lang['supportsID'] ='';
			$this->lang['titlePageEditor'] = $this->lang['addTitle'];
			$strHtmlContent = $this->khithe_display('editor');
			$strHtmlContent = $this->khithe_assign($strHtmlContent, $this->lang);
			return $strHtmlContent;
		}
	}
	
	public function edit_action()
	{
		if($_GET['iframe']=='true')
		{
			$this->lang['sms'] ='';
			if(isset($_POST['txt_supports']))
			{
				$supportname = parent::checkStrMySQL($_POST['txt_supports']);					
				if($supportname==''){
					$this->lang['sms'] = $this->language['Emptysupport'];
				
				}else{
					$done = parent::updateInsertsupport($_POST);
					if($done)  $this->gotowinparent(url_base.'admin/supports');
				}
			}
			
			$resultsupport = parent::getsupportID($this->valUrl(1));
			$row_supports = mysql_fetch_assoc($resultsupport);
			$strHtmlContent = $this->khithe_display('editor');
			$this->lang['titlePageEditor'] = isset($this->lang['editTitle'])?$this->lang['editTitle']:NULL;
			$this->lang['txt_supportsValue'] = isset($_POST['txt_supports']) && $_POST['txt_supports']!=''?$_POST['txt_supports']:$row_supports['Nick'];
			$this->lang['select_yahoo'] =($row_supports['Kind']=='yahoo' || (isset($_POST['kind']) && $_POST['kind']=='yahoo')?' selected="selected" ':'');
			$this->lang['select_skype'] =($row_supports['Kind']=='skype' || (isset($_POST['kind']) && $_POST['kind']=='skype')?' selected="selected" ':'');
			$this->lang['txt_FullnameValue'] = isset($_POST['txt_Fullname']) && $_POST['txt_Fullname']!=''?$_POST['txt_Fullname']:$row_supports['Fullname'];
			$this->lang['txt_orderValue'] = isset($_POST['txt_order']) && $_POST['txt_order']!=''?$_POST['txt_order']:$row_supports['Order'];
			$this->lang['active'] ='edit';
			$this->lang['supportsID'] =$row_supports['ID'];
			$strHtmlContent = $this->khithe_assign($strHtmlContent, $this->lang);
			return $strHtmlContent;
		}
	}
	
	public function index_ajax_action()
	{
		switch ($this->valUrl(1))
		{
			case 'open':
				$arr = explode(',',$this->valUrl(2));
				foreach ( $arr as $ID ){
					$select = parent::getsupportID($ID);
					while($row = mysql_fetch_assoc($select)){
						if($row['Status']=='false'){
							$done = parent::setCheckedsupport($ID,'true');
						}
					}
				}
			break;
			case 'close':
				$arr = explode(',',$this->valUrl(2));
				foreach ( $arr as $ID ){
					$select = parent::getsupportID($ID);
					while($row = mysql_fetch_assoc($select)){
						if($row['Status']=='true'){
							$done = parent::setCheckedsupport($ID,'false');
						}
					}
				}
			break;
			case 'del':
				$arr = explode(',',$this->valUrl(2));
				foreach ( $arr as $ID ){
					$done = parent::delCheckedsupport($ID);	
				}
			break;
		}
		if($this->valUrl(1)!=''&&isset($done)){
			return $this->index_action();
		}else{
			return 'notOK';
		}
				
	}


}
?>